package com.ywxx.dyhelper.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.Switch;

import com.ywxx.dyhelper.R;
import com.ywxx.dyhelper.base.BaseAcitivity;
import com.ywxx.dyhelper.model.TaskConfig;
import com.ywxx.dyhelper.utils.ConstValues;
import com.ywxx.dyhelper.widget.NumberAddSubView;

import androidx.appcompat.app.AppCompatActivity;


/**
 * 万能引流
 */
public class UniversalDrainageActivity extends BaseAcitivity
{

    private NumberAddSubView labNum;
    private NumberAddSubView labOperNum;
    private Switch sw_follow;
    private Switch sw_like;
    private Switch sw_remark;

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_universal_drainage);
        InitUI();
        DataToUI();

    }

    @Override
    protected void InitUI()
    {
        InitTitle();

        labNum = findViewById(R.id.labNum);
        labOperNum = findViewById(R.id.labOperNum);
        sw_follow = findViewById(R.id.sw_follow);
        sw_like = findViewById(R.id.sw_like);
        sw_remark = findViewById(R.id.sw_remark);

        labNum.setMaxValue(8);
        labNum.setMinValue(1);
        labNum.setValue(4);

        labOperNum.setValue(15000);
        labOperNum.setSeekNum(500);
        labOperNum.setMaxValue(60000);

        llStart.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View view)
            {

                appconfig = new TaskConfig();
                appconfig.runtime = labNum.getValue();
                appconfig.oprtime = labOperNum.getValue();
                appconfig.auto_follow = sw_follow.isChecked();
                appconfig.auto_like = sw_like.isChecked();
                appconfig.auto_comment = sw_remark.isChecked();

                ConstValues.SaveValue(UniversalDrainageActivity.this, "runtime" + TaskType, appconfig.runtime);
                ConstValues.SaveValue(UniversalDrainageActivity.this, "opertime" + TaskType, appconfig.oprtime);
                ConstValues.SaveValue(UniversalDrainageActivity.this, "follow" + TaskType, appconfig.auto_follow);
                ConstValues.SaveValue(UniversalDrainageActivity.this, "like" + TaskType, appconfig.auto_like);
                ConstValues.SaveValue(UniversalDrainageActivity.this, "comment" + TaskType, appconfig.auto_comment);

                StartTaskServer(TaskType);
            }
        });
    }

    @Override
    protected void DataToUI()
    {
        int runtime = ConstValues.getIntValue(this, "runtime" + TaskType, 4);
        int opertime = ConstValues.getIntValue(this, "opertime" + TaskType, 15000);
        boolean follow = ConstValues.getBooleanValue(this, "follow" + TaskType, true);
        boolean like = ConstValues.getBooleanValue(this, "like" + TaskType, true);
        boolean comment = ConstValues.getBooleanValue(this, "comment" + TaskType, true);

        labNum.setValue(runtime);
        labOperNum.setValue(opertime);
        sw_follow.setChecked(follow);
        sw_like.setChecked(like);
        sw_remark.setChecked(comment);

    }
}